package com.qiyang.uaa.controller;

import com.alibaba.boot.hsf.annotation.HSFProvider;
import com.qiyang.api.log.LogApi;
import com.qiyang.api.uaa.AuthrizationApi;
import com.qiyang.uaa.dao.entity.SysRole;
import com.qiyang.uaa.service.AuthrizationService;
import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created on 2018/5/8.
 *
 * @author sehuaqi.
 * 描述：
 */
//@RestController
@HSFProvider(serviceInterface = AuthrizationApi.class, serviceVersion = "HSF1")
public class AuthrizationController implements AuthrizationApi {

    Logger logger = LoggerFactory.getLogger(AuthrizationController.class);

    @Autowired
    private LogApi logApi;

    @Autowired
    private AuthrizationService authrizationService;

    @Override
    public String role(@PathVariable("userId") Long userId) {

        String roleCode = null;

        //获取该用户所拥有的角色逻辑，省略
        //List<SysRole> sysRoles = authrizationService.getRolesByUserId(userId);

        String[] roleCodes = new String[]{"admin"};//new String[sysRoles.size()];

//        int i = 0;
//        for (SysRole sysRole : sysRoles) {
//            roleCodes[i] = sysRole.getRoleCode();
//            i++;
//        }

        roleCode = ArrayUtils.toString(roleCodes, "no roles");

        String msg = "获取该用户所拥有的角色逻辑11111:" + userId + ":" + roleCode;

        logger.info(msg);

        logApi.printLog("调用日志服务11111111：" + msg);

        return roleCode;
    }

    @Override
    public String initSysuser(@PathVariable("num") int num) {
        for (int j = 0; j < 50; j++) {
            new Thread() {
                @Override
                public void run() {
                    String result = authrizationService.initSysuser(num);
                }
            }.start();
        }
        return "执行中……";
    }


}
